<template>
	<header>
		<div class="l-content">
			<el-button @click="handleMenu" plain icon="el-icon-menu" size="mini"></el-button>
			<!-- <h3 style="color:#fff" class="btop">首页</h3> -->
<!-- 			<el-breadcrumb separator="/" >
			  <el-breadcrumb-item class="mycolor" v-for="item in title" :key="item.path" :to="{ path: item.path }">{{item.label}}</el-breadcrumb-item>
			</el-breadcrumb> -->
		</div>

		<div class="r-content">
			<el-dropdown trigger="click">
				<span style="color: white;display:flex ; align-items: center;cursor:pointer;">
					<img class="user" :src="userImg"/>
					&nbsp;{{user.nickName}}
				</span>
				  <el-dropdown-menu slot="dropdown">
				    <el-dropdown-item @click.native="profile">个人中心</el-dropdown-item>
				    <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
				  </el-dropdown-menu>
			</el-dropdown>
		</div>
	</header>
</template>

<script>
import {mapState} from 'vuex'
import { getUserProfile } from '../../api/userapi.js'
export default {
	name: 'CommonHeader',
	data() {
		return{
			userImg: require('../assets/images/user.jpg'),
			user: {},
		}
	},
	created() {
	  this.getUser();
	},
	methods:{
		getUser() {
		  getUserProfile().then(response => {
		    this.user = response.data.data;
			this.userImg = 'api'+this.user.avatar
		    this.roleGroup = response.data.roleGroup;
		    this.postGroup = response.data.postGroup;
		  });
		},
		profile(){
			let item = {name:'profile',label:'个人中心',path:'profile/index'}
			this.$router.push({
				  name: item.name
				  // path: item.path,
			})
			this.$store.commit('selectMenu', item)
		},
		handleMenu(){
			this.$store.commit('collapseMenu')
		},
		logout(){
			this.$store.commit('clearMenu')
			localStorage.removeItem("token")
			localStorage.removeItem("menu")
			this.$router.push('/login')
		}
	},
	computed:{
		...mapState({
			tags: state => state.tab.tabsList
		}),
		...mapState({
			title: state => state.breadcrumb.title
		}),
	},
}
</script>

<style>
header{
	display: flex;
	height: 100%;
	width: 100%;
	justify-content: space-between;
	align-items: center;
}
.l-content{
	display:flex;
	align-items:center;
}
.l-content .el-button{
	margin-right: 20px;
}
.r-content{
	margin-right: 0px;
}
.r-content .user{
	width: 40px;
	height: 40px;
	border: 0px solid;
	border-radius: 50%;
}
.btop{
	margin-left: 10px;
}
.mycolor{
	color:white;
}
.mycolor .el-breadcrumb__inner{
  color:white;
}
.mycolor .el-breadcrumb__separator{
	color:white;
}
.el-breadcrumb__item:last-child .el-breadcrumb__inner, 
.el-breadcrumb__item:last-child .el-breadcrumb__inner a, 
.el-breadcrumb__item:last-child .el-breadcrumb__inner a:hover, 
.el-breadcrumb__item:last-child .el-breadcrumb__inner:hover
{
	color:white;
}


</style>
